<tagLib name="html" />

<include file="Public:header" />

<div id="page-body">
    <div class="qan-breadcrumbs search-breadcrumbs"><span><a href="{$_global.site_url}">{$Think.lang.home}</a></span>&nbsp;&gt;&nbsp;<span><a href="{:U('Search/index')}">{$Think.lang.search_advanced}</a></span><notempty name="keyword">&gt;&nbsp;<span class="search-result-for">{$Think.lang.search_result_for|Input::forShow}</span></notempty></div>
    <div id="qan-content">
        <div class="results-container">
            <notempty name="questions">
            <ul class="questions">
                <volist name="questions" id="vo" mod="2">
                <li class="item <eq name="mod" value="0">alt</eq>">
                    <div class="avatar"><a href="{$vo.user_id|format_user_url=$vo['username']}"><img src="{$vo.email|get_avatar}" alt="{$vo.username}" /></a></div>
                    <div class="info">
                        <h3><a href="{$vo.question_id|format_question_url=$vo['title']}">{$vo.title|highlight_keyword=$keyword}</a></h3>
                        <ul class="meta">
                            <li class="stars"><a href="#nogo"><span class="star-count has-stars">{$vo.star_count}</span><span class="star">Stars</span></a></li>
                            <li>{$Think.lang.asked_by} <a href="{$vo.user_id|format_user_url=$vo['username']}">{$vo.username}</a> - </li>
                            <li>{$Think.lang.in} <a href="{$vo.category_id|format_category_url}">{$vo.category_id|get_category_name}</a> - </li>
                            <li>{$vo.answer_count} {$Think.lang.answer_count} - </li>
                            <li><abbr title="{$vo.create_time|format_date}">{$vo.create_time|pretty_date}</abbr></li>
                        </ul>
                    </div>
                </li>
                </volist>
            </ul>
            <div class="pagination">{$pagination}</div>
            <else/>
                <notempty name="keyword">
                <div class="search-no-results">{$Think.lang.search_no_results}</div>
                <div class="search-suggestions">
                    <h2>{$Think.lang.search_suggestion_head}</h2>
                    <ul>
                        {$Think.lang.search_suggestion_body}
                        <li><a href="{:U('Search/google')}">{$Think.lang.search_with_google}</a></li>
                    </ul>
                </div>
                </notempty>
            </notempty>
        </div>
    </div>
    <!-- begin of sidebar -->
    <div id="qan-sidebar">
        <div id="qan-search-options" class="mod">
            <h2>{$Think.lang.search_options}</h2>
            <form method="post" action="{:U('Search/index')}" onsubmit="return validateSearch();">
                <div class="option">
                    <label class="hd" for="keyword">{$Think.lang.search_keyword}:</label>
                    <input id="keyword" type="text" name="keyword" maxlength="100" size="35" value="{$keyword}" />
                </div>
                <div class="option">
                    <label class="hd" for="match-in">Keyword match in:</label>
                    <select id="match-in" name="match_in">
                        <option value="all"> All Q&amp;A</option>
                        <option value="subject"> Questions</option>
                        <option value="best_answer"> Best Answers</option>
                    </select>
                </div>
                <div id="category" class="option">
                    <label class="hd" for="first-level">{$Think.lang.search_category}:</label>
                    <div id="category-container" <notempty name="Think.request.category_id">style="display:none"</notempty>>
                    <select id="first-level" onchange="getCategoryOptions(this,'second-level')">
                        <option value="0">{$Think.lang.all_categories}</option>
                        <volist name="_topCategories" id="vo">
                        <option value="{$vo.category_id}">{$vo.name}</option>
                        </volist>
                    </select>
                    <select id="second-level" style="display:none" onchange="getCategoryOptions(this,'third-level')"></select>
                    <select id="third-level" style="display:none"></select>
                    </div>
                </div>
                <notempty name="Think.request.category_id">
                <div id="reset-category-container" class="option">
                    <label class="hd">{$Think.request.category_id|get_category_name}</label>
                    <p><a href="javascript:void(0)" onclick="resetCategory()">{$Think.lang.search_reset_category}</a></p>
                </div>
                </notempty>
                <div class="option">
                    <label class="hd" for="status">{$Think.lang.search_question_status}:</label>
                    <html:select id="status" name="status" options="statusOptions" selected="statusSelected" />
                </div>
                <div class="option">
                    <label class="hd" for="answer_count">{$Think.lang.search_answer_count}:</label>
                    <html:select id="answer_count" name="answer_count" options="answerCountOptions" selected="answerCountSelected" />
                </div>
                <div class="option">
                    <label class="hd" for="create_time">{$Think.lang.search_create_time}:</label>
                    <html:select id="create_time" name="create_time" options="createTimeOptions" selected="createTimeSelected" />
                </div>
                <div class="option">
                    <input class="button" type="submit" value="{$Think.lang.submit}" />
                    <input id="category_id" type="hidden" name="category_id" value="{$Think.request.category_id}" />
                </div>
            </form>
        </div>
    </div>
</div>

<include file="Public:footer" />

<script type="text/javascript">
function resetCategory(){
    $('#reset-category-container').hide();
    $('#category-container').show();
    $('#category_id').val(0);
}

function validateSearch(){
    var keyword = $.trim($('#keyword').val());
    if(keyword == ''){
        $('#keyword').focus();
        return false;
    }
}
</script>